<? include("/inc/header.html") {} ?>
<style>
.row{
	margin-bottom: 10px;
}
</style>
<div class="col-lg-12" style="overflow: auto;height: 600px;">
	<div class="panel panel">
		<div class="panel-body pan">
			<div class="form-body pal">
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">试卷名称<span
						class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="name" type="text" class="form-control" />
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">考试开始时间<span
						class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="startTime" type="text" class="form-control" readonly="readonly"/>
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">考试结束时间<span
						class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="endTime" type="text" class="form-control" readonly="readonly"/>
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">试卷描述<span
						class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<textarea style="width: 100%;" rows="5" id="description"></textarea>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<input id="id" type="hidden" class="form-control" value="${id}"/>
	<input id="type" type="hidden" class="form-control" value="${type}"/>
	<input id="resourceId" type="hidden" class="form-control" value="${resourceId}"/>
</div>
<script>
$(function(){
	layui.use('laydate', function(){
		  var laydate = layui.laydate;
		  //执行一个laydate实例
		  laydate.render({
		     elem: '#startTime' //指定元素
			  ,type: 'datetime'
		  });
		});
	layui.use('laydate', function(){
		  var laydate = layui.laydate;
		  //执行一个laydate实例
		  laydate.render({
		     elem: '#endTime' //指定元素
			  ,type: 'datetime'
		  });
		});
	init();
});
function init(){
	if($("#id").val() != null 
		&& $("#id").val() != ''
		&& $("#id").val() != 'null'
		&& $("#id").val() != 'undefined'
		&&$("#id").val() != undefined){
		$.ajax({
			type : "post",
			url : "./paperFind.do",
			data : {
				"id" : $("#id").val()
			},
			dataType : "json",
			success : function(data) {
				$("#name").val(data[0].name);
				$("#type").val(data[0].type);
				$("#description").val(data[0].description);
				$("#resourceId").val(data[0].resourceId);
				$("#startTime").val(data[0].startTime);
				$("#endTime").val(data[0].endTime);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
}

function save(){
	var id;
	if($("#id").val() != null 
		&& $("#id").val() != ''
		&& $("#id").val() != 'null'
		&& $("#id").val() != 'undefined'
		&&$("#id").val() != undefined){
		id=$("#id").val();
	}
	
	if($("#name").val()==''){
		layer.msg("请输入试卷名称");
		return false;
	}
	
	var name=$("#name").val(); //    
    var re =/^[\u4e00-\u9fa5_a-zA-Z0-9]{1,50}$/;
	if (!re.test(name)) {
		layer.msg('试卷名称:只允许汉字、英文字母、数字及下划线。50字以内');
		return null;
	}
	
	if($("#description").val()==''){
		layer.msg("请输入试卷描述");
		return false;
	}
	if($("#description").val().length>500){
		layer.msg("试卷描述:500字以内");
		return false;
	}
	$.ajax({
		type : "post",
		url : "./paperAddUpdate.do",
		data : {
			"id" : id,
			"name" : $("#name").val(),
			"description" : $("#description").val(),
			"type" : $("#type").val(),
			"resourceId" : $("#resourceId").val(),
			"startTime" : $("#startTime").val(),
			"endTime" : $("#endTime").val(),
		},
		dataType : "json",
		success : function(data) {
			if(data[0].result == 'success'){
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			}else{
				parent.layer.msg(data[0].msg);
			}
		},
		error : function(data) {
			alert("请求失败");
		}
	});
}
</script>